package com.gougang.interview;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 16978 on 2017/4/7.
 */
public class Person {

    private List<CardBean> holdPokers;
    private String team;
    private Direction direction;

    /**
     * 出牌
     * @return
     */
    public CardBean play() throws Exception {
        if (holdPokers == null ){
            throw new Exception("未能成功获取扑克");
        }

        int size = holdPokers.size();
        if (size > 0) {
            int num = Utils.getRandom(size);
            CardBean card = holdPokers.get(num);
            holdPokers.remove(num);
        }
        return null;
    }

    /**
     * 跟牌
     * @return
     */
    public CardBean follow(CardType type) throws Exception {
        if (holdPokers == null ){
            throw new Exception("未能成功获取扑克");
        }
        int size = holdPokers.size();
        if (size > 0) {
            for (CardBean card : holdPokers) {
                if (card.getType() == type) {
                    CardBean temp = card;
                    holdPokers.remove(card);
                    return card;
                }
            }
        }

        return play();
    }

    public List<CardBean> getHoldPokers() {
        return holdPokers;
    }

    public void setHoldPokers(List<CardBean> holdPokers) {
        this.holdPokers = new ArrayList<CardBean>(holdPokers);
    }

    public String getTeam() {
        return team;
    }

    public void setTeam(String team) {
        this.team = team;
    }

    public Direction getDirection() {
        return direction;
    }

    public void setDirection(Direction direction) {
        this.direction = direction;
    }
}
